package com.mms.action.device;

import java.util.List;

import com.mms.dao.DeviceManagementDao;
import com.mms.entity.Device;
import com.opensymphony.xwork2.Action;

public class AddDeviceAction implements Action{

	private int startpage;
	private String DeNumber;
	private String DeName;
	private List<Device> deviceMessage;
	private int account;
	private boolean addSuccess;
	
	public int getStartpage() {
		return startpage;
	}


	public void setStartpage(int startpage) {
		this.startpage = startpage;
	}

	public String getDeNumber() {
		return DeNumber;
	}


	public void setDeNumber(String deNumber) {
		DeNumber = deNumber;
	}


	public String getDeName() {
		return DeName;
	}


	public void setDeName(String deName) {
		DeName = deName;
	}


	public List<Device> getDeviceMessage() {
		return deviceMessage;
	}


	public void setDeviceMessage(List<Device> deviceMessage) {
		this.deviceMessage = deviceMessage;
	}


	public int getAccount() {
		return account;
	}


	public void setAccount(int account) {
		this.account = account;
	}


	public boolean isAddSuccess() {
		return addSuccess;
	}


	public void setAddSuccess(boolean addSuccess) {
		this.addSuccess = addSuccess;
	}


	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		
		DeviceManagementDao dmd = new DeviceManagementDao();
		Device device = new Device();
		if(DeNumber.equals("")){
			device.setDName(DeName);
			if(dmd.AddDevice(device)){
				addSuccess = true;
			}else{
				addSuccess = false;
			}
		}
		else {
			device.setDId(Integer.parseInt(DeNumber));
			device.setDName(DeName);
			if(dmd.AddDevice(device)){
				addSuccess = true;
			}else{
				addSuccess = false;
			}
		}
		
		deviceMessage = dmd.getDevice(startpage);
		account = dmd.getcount();
		return "success";
	}

}
